<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">

        <link rel="shortcut icon" href="<!--{eval echo register_static('img/touch-icon-57x57.png');}-->">

        <title>粉粉管理系统</title>

        <!-- Bootstrap core CSS -->
        <link href="<!--{eval echo register_static('css/bootstrap.min.css');}-->" rel="stylesheet">
        <link href="<!--{eval echo register_static('css/bootstrap-reset.css');}-->" rel="stylesheet">

        <!--Animation css-->
        <link href="<!--{eval echo register_static('css/animate.css');}-->" rel="stylesheet">

        <!--Icon-fonts css-->
        <link href="<!--{eval echo register_static('assets/font-awesome/css/font-awesome.css');}-->" rel="stylesheet" />
        <link href="<!--{eval echo register_static('assets/ionicon/css/ionicons.min.css');}-->" rel="stylesheet" />
        
        <link href="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.css');}-->" rel="stylesheet">
        
        <!-- Plugins css -->
        <link href="<!--{eval echo register_static('assets/modal-effect/css/component.css');}-->" rel="stylesheet">

        <!-- DataTables -->
        <link rel="stylesheet" href="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.css" rel="stylesheet');}-->" />

        <!-- Custom styles for this template -->
        <link href="<!--{eval echo register_static('css/style.css');}-->" rel="stylesheet">
        <link href="<!--{eval echo register_static('css/helper.css');}-->" rel="stylesheet">
        
        <!-- My styles for this template -->
        <link href="<!--{eval echo register_static('css/common.css');}-->" rel="stylesheet">

    </head>

    <body>

        <!-- Aside Start-->
        <!--{template admin_v2/leftside}-->
        <!-- Aside Ends-->
        <!--Main Content Start -->
        <section class="content">
            <!-- Header -->
            <!--{template admin_v2/header}-->
            <!-- Header Ends -->
            <!-- Page Content Start -->
            <!-- ================== -->
            <div class="wraper container-fluid diary-topics">
            
            <div class="row">
                 <div class="col-md-12">
                     <div class="panel panel-default">
                        <div class="panel-heading">
                            <h3 class="panel-title">手账资源</h3>
                        </div>
						<br/>
                        <div class="row">
							<div class="col-md-1">
                                    <buttton class="btn btn-primary" id="newsource">新建资源</buttton>
								</div>
							<div class="col-md-2 form-group">
									<div class="form-inline">
										<div style="display: inline-block; padding-right: 20px">筛选：</div>
										<div class="form-group">
											<select name="type" id="selectPlannerType" class="form-control myChoose">
												<option value="6">标签</option>
												<option value="7">背景</option>
												<option value="8">贴纸</option>
												<option value="9">花边笔</option>
												<option value="11">边框</option>
												<option value="12">插件</option>
												<option value="10">模板</option>
												<option value="13">手账引导器</option>
											</select>
										</div>
								 </div>
							</div>
                            <div class="col-md-4">
                                 <ul class="pagination" style="margin-top: -1px;" id="pagination1"></ul>
                             </div>
                        </div>
                        <div class="panel-body">
                                <div class="row">
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <table id="datatable" class="table table-striped table-bordered">
                                            <thead>
                                                <tr>
                           							 <th>ID</th>
                            						 <th>封面</th>
                            						 <th>名称</th>
                          							 <th>状态</th>
                                                	 <th>下载量</th>
													 <th>上线时间</th>
													 <th>推荐</th>
													 <th>标签</th>
													 <th>管理</th>
												</tr>
                                            </thead>

                                            <tbody id="tbody_html">


                                             </tbody>
                                         </table>
                                     </div>
                                 </div>
                            </div>
                     </div>
                 </div>
            </div>
            <!-- Page Content Ends -->
            <!-- ================== -->

            <!-- Footer Start -->
            <!--{template admin_v2/footer}-->
            <!-- Footer Ends -->
            </div>
        </section>
        <!-- Main Content Ends -->


        <!-- js placed at the end of the document so the pages load faster -->
        <script src="<!--{eval echo register_static('js/jquery.js');}-->"></script>
        <script src="<!--{eval echo register_static('js/bootstrap.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('js/pace.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('js/wow.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('js/jquery.nicescroll.js');}-->" type="text/javascript"></script>

		<script src="<!--{eval echo register_static('js/jquery.app.js');}-->"></script>
		<script src="<!--{eval echo register_static('js/handlebars-v4.0.5.js');}-->"></script>
		<script src="<!--{eval echo register_static('js/handlebars-planner-helper.js');}-->"></script>
        <script src="<!--{eval echo register_static('js/jqPaginator.js');}-->"></script>
		<script src="<!--{eval echo register_static('layer/layer.js');}-->"></script>
        <script src="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('assets/datatables/dataTables.bootstrap.js');}-->"></script>
        <script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.js');}-->"></script>
        <script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.init.js');}-->"></script>
        
        <!-- Modal-Effect -->
        <script src="<!--{eval echo register_static('assets/modal-effect/js/classie.js');}-->"></script>
        <script src="<!--{eval echo register_static('assets/modal-effect/js/modalEffects.js');}-->"></script>
        <script id="list" type="text/template">
            {{#.}}
                <tr>
                    <td>{{this.id}}</td>
                    <td ><img  style="width:30px;height:30px;" src="{{this.cover_s}}" /></td>
                    <td>{{this.name}}</td>
                    <td>{{{displayStatus this.status}}}</td>
                    <td>{{this.sold_count}}</td>
                    <td>{{{displayTime this.time}}}</td>
                    <td>{{{displayLabel this.label}}}</td>
                    <td>{{this.tag}}</td>
                    <td>
                        <button class="btn btn-primary editdata"  data-type="{{this.type}}" data-id="{{this.id}}">编辑</button>
                        <button class="btn btn-info">打包</button>
                    </td>
                </tr>
            {{/.}}
        </script>
        <script id="newFrame" type="text/template">
                {{#.}}
                <div class="container">
                    <form action="admin.php" method="get" id="sourcedata">
                        <div class="row">
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="labelid" class="control-label">id号</label>
                                    <input class="form-control" id="labelid" type="text"  placeholder="id" name="id" value="{{this.id}}">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="labelname" class="control-label">名称</label>
                                    <input class="form-control" id="labelname" type="text" placeholder="name" name="name" value="{{this.name}}" >
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="labelcuid" class="control-label">作者UID</label>
                                    <input class="form-control" id="labelcuid" type="text" placeholder="CUID" name="cuid" value="{{this.cuid}}" >
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-2">
                                <div class="form-group">
                                    <label for="labeltype" class="control-label">类型</label>
                                    <select name="type"  class="form-control" id="labeltype">
                                        {{{selectType this.type}}}
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-2">
                                <div class="form-group">
                                    <label for="labeltag" class="control-label">标签</label>
                                    <select name="tag" class="form-control" id="labeltag">
                                        {{{displayTag this.tag}}}
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-2">
                                <div class="form-group">
                                    <label for="labelstatus" class="control-label">状态</label>
                                    <select name="status" class="form-control" id="labelstatus">
                                      {{{selectStatus this.status}}}
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-2">
                                <div class="form-group">
                                    <label for="labellabel" class="control-label">推荐</label>
                                    <select name="label" class="form-control" id="labellabel">
                                        {{{displaylabelSelect this.label}}}
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-2">
                                <div class="form-group">
                                    <label for="labelkind" class="control-label">种类</label>
                                    <select name="kind" class="form-control" id="labelkind">
                                        {{{displaykindSelect this.kind}}}
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-2">
                                <div class="form-group">
                                    <label for="labelcategory" class="control-label">类别</label>
                                    <select name="category" class="form-control" id="labelcategory">
                                        {{{displayCategorySelect this.type this.category}}}
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="labelos" class="control-label">系统</label>
                                    <select name="os" class="form-control" id="labelos">
                                        {{{displayOsSelect this.os}}}
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="labelvers" class="control-label">最低版本号</label>
                                    <input class="form-control" id="labelvers" type="text"  placeholder="ios|android|iospro|" name="versionsupport" value="{{this.versionsupport}}">
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="labelcover" class="control-label">快捷预览图</label>
                                    <input class="form-control" id="labelcover" type="text"  placeholder="快捷预览图" name="cover" value="{{this.cover}}">
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="labelcover_s" class="control-label">预览图</label>
                                    <input class="form-control" id="labelcover_s" type="text"  placeholder="预览图" name="cover_s" value="{{this.cover_s}}">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="labelzip_url" class="control-label">包链接</label>
                                    <input class="form-control" id="labelzip_url" type="text"  placeholder="包链接" name="zip_url" value="{{this.zip_url}}">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="labelthumbnail" class="control-label">图信息</label>
                                    <input class="form-control" id="labelthumbnail" type="text"  placeholder="图信息" name="thumbnail" value="{{this.thumbnail}}">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="labeldata" class="control-label">dataJson</label>
                                    <input class="form-control" id="labeldata" type="text"  placeholder="json信息" name="data" value="{{this.data}}">
                                </div>
                            </div>
                        </div>
                        <input type="hidden" name="action" value="{{this.action}}">
                        <button type="button" style="float:right" id="sub" class="btn btn-primary">提交</button>
                    </form>
                </div>
            {{/.}}
        </script>
		<script>
            $(function () {
                $.fn.serializeObject = function()
                {
                    var o = {};
                    var a = this.serializeArray();
                    $.each(a, function() {
                        if (o[this.name] !== undefined) {
                            if (!o[this.name].push) {
                                o[this.name] = [o[this.name]];
                            }
                            o[this.name].push(this.value || '');
                        } else {
                            o[this.name] = this.value || '';
                        }
                    });
                    return o;
                };
            })
            $(document).off('#sub').on('click','#sub',function(){
                var data = {};
                data = $("#sourcedata").serializeObject();
                $.ajax(
                        {
                            dataType:   "json",
                            url     :   'admin.php?ac=admin&op=start&do=planner',
                            type    :   "GET",
                            data    :   data,
                            success :   function(da)
                            {
                                if(da.result == true){
                                   layer.msg('操作成功!');
                                }else{
                                    layer.msg('操作失败');
                                }
                                _where={'type':data.type,'action':'getPlannerList'};
                                request();
                            }
                        });
                layer.closeAll();
            });
            $(document).off('.editdata').on('click','.editdata', function () {
                var where = {'id':$(this).data('id'),'type':$(this).data('type'),'action':'getPlannerDetail'};
                $.ajax(
                        {
                            dataType:   "json",
                            url     :   'admin.php?ac=admin&op=start&do=planner',
                            type    :   "GET",
                            data    :   where,
                            async   :   false,
                            success :   function(d)
                            {
                                d.result['action'] = 'editPlanner';
                                var data = Handlebars.compile($('#newFrame').html());
                                layer.open({
                                    type: 1,
                                    title:'资源详情页',
                                    skin: 'layui-layer-rim', //加上边框
                                    area: ['65%', '70%'], //宽高
                                    content: data(d.result)
                                });
                            }
                        });
            });
            $(document).off('#labeltype').on('change','#labeltype', function () {
                var type=$(this).val();
                var res ={};
                var str = '';
                res = getPlannerCategory(type);
                if(res){
                    for(var i in res){
                        str+='<option  value="'+res[i]['cid']+'">'+res[i]['name']+'</option>';
                    }
                }
                $('#labelcategory').html(str)
            });
            $(document).off('#newsource').on('click','#newsource', function () {
                var data = Handlebars.compile($('#newFrame').html());
                layer.open({
                    type: 1,
                    title:'资源详情页',
                    skin: 'layui-layer-rim', //加上边框
                    area: ['65%', '70%'], //宽高
                    content: data({'action':'addPlanner'})
                });
            });

            var _where={'type':6,'action':'getPlannerList'};
            $(document).off('#selectPlannerType').on('change','#selectPlannerType',function(){
                 _where={'type':$(this).val(),'action':'getPlannerList'};
                $('#pagination1').jqPaginator('option',{
                    currentPage: 1
                });
                request();
            });
            $(function(){
                $.jqPaginator('#pagination1',{
                    totalPages: 100,
                    visiblePages: 5,
                    currentPage: 1,
                    onPageChange: function (num, type) {
                        _where['start'] = (num-1)*20;
                        _where['length'] = 20;
                        request();
                    }
                });
            });
	         var request = function(){
				 var lists = Handlebars.compile($('#list').html());
				 $.ajax(
						 {
							 dataType:   "json",
							 url     :   'admin.php?ac=admin&op=start&do=planner',
							 type    :   "GET",
							 data    :   _where,
							 success :   function(data)
							 {
								 $("#tbody_html").empty().append(lists(data.result));
							 }
						 });
			 };
			//第一次进来访问
			request();
        </script>
    </body>
</html>
